package cn.edu.scnu.mapper;

import cn.edu.scnu.entity.Movie;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SearchMapper {

    @Select("SELECT * FROM tb_movie WHERE movie_name LIKE CONCAT('%', #{query}, '%') " +
            "OR movie_id IN (SELECT movie_id FROM tb_staff WHERE staff_name LIKE CONCAT('%', #{query}, '%')) " +
            "LIMIT #{offset}, #{limit}")
    List<Movie> searchMovies(@Param("query") String query, @Param("offset") int offset, @Param("limit") int limit);

    @Select("SELECT COUNT(*) FROM tb_movie WHERE movie_name LIKE CONCAT('%', #{query}, '%') " +
            "OR movie_id IN (SELECT movie_id FROM tb_staff WHERE staff_name LIKE CONCAT('%', #{query}, '%'))")
    int countSearchMovies(@Param("query") String query);
}
